package com.tech.tool.repository;

import com.tech.tool.dataobject.ApiReview;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface ApiReviewRepository extends JpaRepository<ApiReview, Integer> {

    List<ApiReview> findByApiDelete(Integer delete);

    List<ApiReview> findByApiDeleteAndUserId(Integer delete, Integer userId);

    Page<ApiReview> findByApiDeleteAndProjectId(Integer delete, Integer projectId, Pageable pageable);

    @Query(value = "select * from api_review where api_delete=?1 and  if(?2 !=0, project_id=?2, 1=1) and  if(?3 !=0, user_id=?3, 1=1) and if(?4 !='', api_name like ?4, 1=1)" ,nativeQuery = true)
    Page<ApiReview> findOptionalByApiDeleteAndProjectIdAndUserIdAndApiName(Integer delete, Integer projectId, Integer userId, String apiName, Pageable pageable);


}
